﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Yuekao.API.Read.Command;
using Yuekao.Domain.API;
using Yuekao.Domain.dto;
using Yuekao.Domain.Entitys;

namespace Yuekao.API.Read.Controllers
{
    /// <summary>
    /// 基础数据 -API -读
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagementController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ManagementController> logger;
        public ManagementController(IMediator mediator, ILogger<ManagementController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="userPass">密码</param>
        /// <returns>返回任务</returns>
        [HttpGet]

        public Task<APIResult<List<UserDTO>>> Login(string userName, string userPass)
        {
            try
            {
                logger.LogInformation("调用了 登录 方法 ");
                LoginCommand command = new LoginCommand();
                command.UserName = userName;
                command.UserPass = userPass;
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError($"登录异常,异常为:{ex.Message}");
                throw;
            }
        }
        /// <summary>
        /// 流程设计列表显示
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<APIPagging<WorkflowDefinitionModel>>> DefinitionShow(int pageIndex, int pageSize)
        {
            WorkflowDetinitionShowCommand command = new WorkflowDetinitionShowCommand();
            command.pageSize = pageSize;
            command.pageIndex = pageIndex;
            return mediator.Send(command);
        }
        /// <summary>
        /// 流程实例列表显示
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<APIPagging<WorkflowInstanceModel>>> InstanceShow(int pageIndex, int pageSize)
        {
            WorkflowInstanceShowCommand command = new WorkflowInstanceShowCommand();
            command.pageSize = pageSize;
            command.pageIndex = pageIndex;
            return mediator.Send(command);
        }
        ///// <summary>
        ///// 流程列表显示
        ///// </summary>
        ///// <param name="pageIndex">页码</param>
        ///// <param name="pageSize">页容量</param>
        ///// <param name="UserId">用户id</param>
        ///// <returns>返回任务</returns>
        //[HttpGet]
        //public Task<APIResult<APIPagging<AuditModel>>> AuditShow(int pageIndex, int pageSize, int UserId)
        //{
        //    AuditShowCommand command = new AuditShowCommand();
        //    command.pageSize = pageSize;
        //    command.pageIndex = pageIndex;
        //    command.UserId = UserId;
        //    return mediator.Send(command);
        //}
    }
}
